package com.baosight.sczx.common.zm.cInterface.cl;

import java.util.HashMap;
import java.util.Map;

import com.baosight.iplat4j.core.ei.EiInfo;
import com.baosight.iplat4j.core.spring.SpringApplicationContext;
import com.baosight.iplat4j.core.threadlocal.UserSession;
import com.baosight.iplat4j.dao.Dao;
import com.baosight.sczx.common.zm.basetools.StaticTools;

/**
 * 隐患处理模块 接口
 * <p>Title: RiskHandle.java</p>
 * <p>Description: </p>
 * <p>Copyright: Baosight Software LTD.co Copyright (c) 2002</p>
 * <p>Company: Baosight Software</p>
 * @author 严洪浩
 * @version 1.0
 * <pre>Histroy:
 *          2011-8-6 上午07:38:58  严洪浩  Create
 *</pre>
 */
public class RiskHandle {
	
	private static Dao dao = (Dao)SpringApplicationContext.getBean("dao");
	
	/**
	 * 在隐患处理模块 新增隐患处理记录
	 * 引用类：ServceZMCL70.java
	 * <p>Function: Insert</p>
	 * <p>Description: </p>
	 * <p>return value:boolean</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-8-6上午07:40:27 严洪浩
	 * </p>
	 *
	 */
	public static boolean Insert(EiInfo inInfo, String fdKeyId) {
		try {
			String fdRiskRecordId = inInfo.getCellStr("result", 0, "fdKeyId");//隐患记录ID
			String fdStatus = "1";//状态
			String fdIsPenalty = "否";
			String fdSuggestion = inInfo.getCellStr("result", 0, "fdSuggestion");//处理意见
			String fdHandleDate = StaticTools.getDate();//处理日期
			if(null == UserSession.getUserId() || null == UserSession.getInSessionProperty("UserCname")) {
				return false;
			}
			
			String fdHandlePeopleId = UserSession.getUserId().toString();//操作人ID
			String fdHandlePeople = UserSession.getInSessionProperty("UserCname").toString();//操作人Name
			
			Map<String, String> _argMap = new HashMap<String, String>();
			_argMap.put("fdKeyId", fdKeyId);
			_argMap.put("fdRiskRecordId", fdRiskRecordId);
			_argMap.put("fdStatus", fdStatus);
			_argMap.put("fdIsPenalty", fdIsPenalty);
			_argMap.put("fdPenalty", "0");
			_argMap.put("fdSuggestion", fdSuggestion);
			_argMap.put("fdHandleDate", fdHandleDate);
			_argMap.put("fdHandlePeopleId", fdHandlePeopleId);
			_argMap.put("fdHandlePeople", fdHandlePeople);
			_argMap.put("fdCreateTime", StaticTools.getDateTime());//创建时间
			
			dao.insert("ZMCLRiskHandle.insert", _argMap);
		} catch (Exception e) {
			System.out.println("在隐患处理模块 新增隐患处理记录异常：" + e.getMessage());
			return false;
		} 
		return true;
	}
	
	/**
	 * 隐患处理模块 罚款后修改隐患处理记录状态
	 * 引用类：ServceZMCL70.java
	 * <p>Function: Update</p>
	 * <p>Description: </p>
	 * <p>return value:int</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-8-15上午04:47:17 严洪浩
	 * </p>
	 *
	 */
	public static int Update(EiInfo inInfo) {
		int count = 0;
		
		try {
			String fdKeyId = inInfo.getCellStr("result", 0, "fdRiskHandleId");//隐患处理记录ID
			String fdPenaltyId = inInfo.getCellStr("result", 0, "fdPenaltyId");//罚款单ID
			String fdPenalty = inInfo.getCellStr("result", 0, "fdPenalty");//罚款金额
			
			Map<String, String> _argMap = new HashMap<String, String>();
			_argMap.put("fdKeyId", fdKeyId);
			_argMap.put("fdIsPenalty", "是");//是否罚款
			_argMap.put("fdPenaltyId", fdPenaltyId);
			_argMap.put("fdPenalty", fdPenalty);

			count = dao.update("ZMCLRiskHandle.updatePenalty", _argMap);
		} catch (Exception e) {
			System.out.println("隐患处理模块 罚款后修改隐患处理记录状态异常：" + e.getMessage());
		}
		
		return count;
	}
	
	/**
	 * 作废\关闭\复查通过后修改状态
	 * fdKeyId 隐患记录ID
	 * <p>Function: InvalidOrClose</p>
	 * <p>Description: </p>
	 * <p>return value:int</p>
	 * <p>throws Exception:</p>
	 * <p>History:
	 *    2011-10-11下午03:11:21 严洪浩
	 * </p>
	 *
	 */
	public static int InvalidOrClose(String fdKeyId) {
		int count = 0;
		
		try {
			Map<String, String> _argMap = new HashMap<String, String>();
			_argMap.put("fdKeyId", fdKeyId);
			count = dao.update("ZMCLRiskHandle.modifyRechecked", _argMap);
		} catch (Exception e) {
			System.out.println("隐患处理模块 罚款后修改隐患处理记录状态异常：" + e.getMessage());
		}
		
		return count;
	}
	
}
